<template>
  <div class="app-container">
    <div v-show="!showAdd.showcp">
      <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="项目名称" prop="fname">
          <el-input
            v-model="queryParams.fname"
            placeholder="请输入储备项目名称"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="实例ID" prop="instanceId">
          <el-input
            v-model="queryParams.instanceId"
            placeholder="请输入流程实例ID"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-row :gutter="10" class="mb8" >
        <el-col :span="1.5">
          <el-button
            type="primary"
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
          >新增
          </el-button>
        </el-col>
        <right-toolbar v-show="showSearch" :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>

      <el-table v-loading="loading" :data="gbzcbList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center"/>
        <el-table-column label="编号" align="center" prop="fId" />
        <el-table-column label="名称" align="center" prop="fName" />
        <el-table-column label="项目编码" align="center" prop="fNumber"/>
        <el-table-column label="创建时间" align="center" prop="createTime"/>
<!--        <el-table-column label="申请人" align="center" prop="applyUserName"/>-->
<!--        <el-table-column label="申请时间" align="center" prop="applyTime" width="120">-->
<!--          <template slot-scope="scope">-->
<!--            <span>{{ parseTime(scope.row.applyTime, '{y}-{m}-{d}') }}</span>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column label="当前任务名称" align="center" prop="taskName" width="150"/>-->
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <ApplyBefore
              v-show="!scope.row.instanceId"
              :row="scope.row"
              :handleUpdate="handleUpdate"
              :handleGetData="handleGetData"
              :handleDelete="handleDelete"
              :requestMapping="requestMapping"
              @getList="getList"
            ></ApplyBefore>
            <ApplyAfter
              v-show="scope.row.instanceId"
              :row="scope.row"
              :handleGetData="handleGetData"
              :taskId="scope.row.taskId?scope.row.taskId:'0'"
              :type="scope.row.type"
              @getList="getList"
            ></ApplyAfter>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
    <CreateProject v-if="showAdd.showcp" :showAdd="showAdd" :formData="formData" :otherInfo="otherInfo"></CreateProject>
  </div>
</template>

<script>
import { listGbzcbSimple, getGbzcb, delGbzcb, addGbzcb, updateGbzcb, exportGbzcb } from '@/api/business/gbzcb'
import ApplyBefore from '@/components/Activiti/ApplyBefore/ApplyBefore'
import ApplyAfter from '@/components/Activiti/ApplyAfter/ApplyAfter'
import CreateProject from '@/views/business/gbzcb/createProject'
import CbProStatisticTable from '@/views/business/gbzcb/CbProStatisticTable'
import { getxzqGeom } from '@/api/gbznt/gbzCommon'
import Bus from "@/utils/bus"
import globalVariable from '@/utils/Global/globalVariable'



export default {
  name: 'GbzcbPro',
  components: {
    ApplyBefore,
    ApplyAfter,
    CreateProject,
    CbProStatisticTable
  },
  data() {
    return {
      showTable: true,
      showAdd: { showcp: false, readonly: false, tododeal: false },
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: false,
      // 总条数
      total: 0,
      // 请假表格数据
      gbzcbList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 请假类型字典
      typeOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        fname: null,
        leaveStartTime: null,
        leaveEndTime: null,
        applyUserId: null,
        applyUserName: null,
        applyTime: null,
        instanceId: null
      },
      // 表单参数
      formData: {
        fName: null,
        fNumber: null,
        fType: null,
        fYear: null,
        fRegion: null,
        fAmount: null,
        fSchedule: null,
        fXmin: null,
        fXmax: null,
        fYmin: null,
        fYmax: null,
        fArea: null,
        fDesc: null,
        instanceId: null,
        processKey: null,
        createBy: null,
        fAttachment: null,
        geom: null,//项目范围
        fAddress: null,
        fContent: null,
        fIrrigatePen: null,
        fIrrigateWei: null,
        fIrrigateGuan: null,
        fBenefifName: null,
        fBenefifArea: null,
        fPlanTotal: null,
        fPlanCentral: null,
        fPlanShixian: null,
        fPlanSelf: null,
        fId: null,
        applyUserId: null,
        applyUserName: null,
        applyTime: null,
        delFlag: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        fXzqdm: null,
        fXzqmc: null,
        fRedlineFeas: null,//与生态红线相交图形
        fWaterprotectFeas: null,//与水源地保护相交图形
      //  fLandspaceFeas: null,//与国土空间规划相交图形
        fNaturalreserveFeas: null,//与自然保护区规划相交图形
        fRedlineTable: null,//与生态红线相交统计信息
        fWaterprotecTable: null,//与水源地保护相交统计信息
       // fLandspaceTable: null,//与国土空间规划相交统计信息
        fNaturalreserveTable: null,//与自然保护区规划相交统计信息
        fScaleArea: null,//建设规模（万亩）
        fState: null,//建设状态 0代表存在 2代表删除,1表示通过审批，正式成为储备项目
        fHistorygbzFeas: null,//与历史项目相交图形
        fHistorygbzTable: null,//与历史项目相交的统计信息
        taskId: null,
        taskName: null,
        fFarmland2019Feas: null,//与耕地相交矢量
        fFarmland2019Table: null,//与耕地相交统计信息
      },
      formDataNew: {},
      // 表单校验
      rules: {
        fname: [
          { required: true, message: '名称不能为空', trigger: 'blur' }
        ],
        fxzqdm: [
          { required: true, message: '项目所在区县不能为空', trigger: 'blur' }
        ],
        content: [
          { required: true, message: '建设内容不能为空', trigger: 'blur' }
        ]
      },
      requestMapping: '/gbzcbproject',
      otherInfo:{
        proId:"01"
      }
    }
  },
  created() {
    this.formDataNew = this.formData


    this.getList()

  },
  mounted() {
    //2023年3月24日 LQ 绥化这里可以免登录，因此修改下函数
      globalVariable.getRegionAndSettingAxiosNotLgion();
  },
  methods: {
    /** 查询请假列表 */
    getList() {
      this.loading = true
      listGbzcbSimple(this.queryParams).then(response => {
        this.gbzcbList = response.rows
        this.total = response.total
        this.loading = false
        this.otherInfo.proId= response.total
      })
    },
    getXzqGeo(){
      let that=this;
      getxzqGeom().then(res => {
        let row=res.rows[0];

      })
    },

    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        fId: null,
        fType: null,
        fName: null,
        fXzqdm: null,
        content: null,
        // leaveStartTime: null,
        // leaveEndTime: null,
        // totalTime: null,
        // realityStartTime: null,
        // realityEndTime: null,
        applyUserId: null,
        applyUserName: null,
        applyTime: null,
        instanceId: null,
        processKey: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      //  this.reset();
      if(this.globalVar.mmConfig.mapRegion.f_levels===-1){
        this.$message.error('正在加载底层数据中，请稍后再试');
        return;
      }
      this.formDataNew.fXzqdm=this.globalVar.mmConfig.mapRegion.f_regioncode;
      this.formDataNew.fXzqmc=this.globalVar.mmConfig.mapRegion.f_name;
      this.formData = this.formDataNew
      this.showTable = false
      this.showAdd.readonly = false
      this.showAdd.tododeal = false
      this.showAdd.showcp = true
      /*this.open = true;
      this.title = "预添加项目储备库";*/
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      //  this.reset();
      this.showAdd.showcp = false
      const id = row.fId || this.ids
      getGbzcb(id).then(response => {
        this.formData = response.data
        this.showTable = false
        this.showAdd.readonly = false//允许编辑
        this.showAdd.showcp = true

      })
    },
    /** 查看按钮操作 */
    handleGetData(row) {
      //  this.reset();
      this.showAdd.showcp = false
      const id = row.fId || this.ids
      getGbzcb(id).then(response => {
        this.formData = response.data
        // this.formData.taskId
        this.showTable = false
        this.showAdd.readonly = true//不允许编辑
        this.showAdd.showcp = true
      })
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.fId || this.ids
      this.$confirm('是否确认删除预储备编号为"' + ids + '"的数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return delGbzcb(ids)
      }).then(() => {
        this.getList()
        this.msgSuccess('删除成功')
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams
      this.$confirm('是否确认导出所有储备数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return exportGbzcb(queryParams)
      }).then(response => {
        this.download(response.msg)
      })
    }
  },
  watch: {
    'showAdd.showcp'(nValue, oValue) {
      if (nValue === false) {
        //this.showTable = true
        this.getList()
      }
    },
  }
}
</script>
